package dem1;

import javax.swing.tree.TreeNode;
import java.util.HashMap;
import java.util.Map;

/**
 * Created with Intellij IDEA.
 * Description:
 * User: 33013
 * Date: 2023-05-17
 * Time: 0:35
 */
public class Test {
    public static void main(String[] args) {
        int[] arr = {1,2,1,0,1};
        boolean b = containsNearbyDuplicate(arr,4);
    }
    public static boolean containsNearbyDuplicate(int[] nums, int k) {
        Map<Integer, Integer> map = new HashMap<Integer, Integer>();
        int length = nums.length;
        for (int i = 0; i < length; i++) {
            int num = nums[i];
            if (map.containsKey(num) && i - map.get(num) <= k) {
                return true;
            }
            map.put(num, i);
        }
        return false;
    }

    public static int getHight(TreeNode head){
        if (head == null){
            return 0;
        }
        int left = getHight(head.left);
        int right = getHight(head.right);
        return Math.max(left,right) + 1;
    }

    public TreeNod find(TreeNode root, int val){
        if (root == null){return null;}
        if (root.val == val){return root;}
        TreeNode left = find(root.left, val);
        if (left != null){
            return left;
        }
        TreeNode right = find(root.right, val);
        return right;
    }
}
